<?php

class Upload extends PC_Controller {



//直接二进制接收  cao


    public function test(){
		$list = $this->db->where("site_id = 1 and token != '6191b895e65cf80e73a92a27e70d4225'")->get('chat_user_connection');
		var_dump($list->result_array());
	}

	public function uploadWithBinary()
	{
		$save_path = $_SERVER['DOCUMENT_ROOT'].'/data/uploads/';
		$save_name = md5(uniqid().time()).'.png';
		$file_path =  $save_path.$save_name;
		$http_path = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' .$_SERVER['HTTP_HOST'].'/data/uploads/'.$save_name;
         //var_dump($_FILES);
		//return;
		$content = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents('php://input');
		if(empty($content)){
			if(file_exists($_FILES['image']['tmp_name'])){
				move_uploaded_file($_FILES['image']['tmp_name'], $file_path);
			}
		}else {
			file_put_contents($file_path, $content);
		}

		$this->ajaxReturnJson(['ret'=>0,'data'=>['path'=>$http_path]]);


	}

	public function ajaxReturnJson($data){

		header('Content-type: application/json');
		echo json_encode($data);
	}







}
